package com.sky.config;

import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/*
* 配置阿里云 oss 工具类对象
* */
@Slf4j
@Configuration
public class AliossConfig {
    // 创建Bean AilossUtil 对象
    @Bean
    @ConditionalOnMissingBean
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties){
        log.info("开始创建阿里云oss对象：{}",aliOssProperties);
        // 创建 AliOssUtil 工具类
        return AliOssUtil.builder()
                .endpoint(aliOssProperties.getEndpoint())
                .bucketName(aliOssProperties.getBucketName())
                .accessKeyId(aliOssProperties.getAccessKeyId())
                .accessKeySecret(aliOssProperties.getAccessKeySecret())
                .build();
    }
}
